class Solution {
    /**
     * G(n)=G(0)∗G(n−1)+G(1)∗(n−2)+...  卡特兰数
     */
    public int numTrees(int n) {
            int[] dp = new int[n + 1];
            dp[0] = 1;
            dp[1] = 1;
            if(n<2){
                return dp[n];
            }
            dp[2] = 2;

            for(int i = 3; i <= n; i ++) {
                for(int j = 1; j <= i; j ++) {
                    dp[i] += dp[j - 1] * dp[i - j];
                }
            }
            return dp[n];
        }
}